home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / c_toolbx.arc / VIEWFIND.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-03-30  |  1.5 KB  |  50 lines

  1. /* viewfinf.c file - moves to new positions in the file */
  2. #include "stdio.h"
  3. #include "cminor.h"
  4. #include "viewparm.h"
  5. long top_of_page ;   /* position in file of top of display page */
  6. long where_now() ;   /* returns current file position  */
  7.  
  8. int move_forward(nlines)        /* move forward n lines     */
  9.   int nlines  ;             /* number of lines to move    */
  10.   {
  11.     int c ;                /* hold chars read here     */
  12.  
  13.     move_to(top_of_page) ;        /* start at top of page     */
  14.     while( nlines > 0 )
  15.       { c = get_next_char() ;
  16.     if( c == END_LINE )        /* check for end of line    */
  17.       nlines = nlines - 1 ;
  18.     if( c == EOF_MARK )        /* check for end of file    */
  19.       { set_top_page();        /* yes - mark as top of page    */
  20.         return    ;        /* and exit            */
  21.       }
  22.       }
  23.     set_top_page()    ;        /* mark this top of page    */
  24.   }
  25.  
  26.   int move_backward(nlines)        /* move backward n lines    */
  27.   int nlines  ;             /* number of lines to move    */
  28.   {                    /* (zero = start of this line)    */
  29.     int c ;                /* hold char here        */
  30.  
  31.     move_to(top_of_page) ;        /* start at top of page     */
  32.     nlines = nlines + 1  ;        /* add one for current line    */
  33.     while( nlines > 0 )
  34.       { c = get_previous_char() ;
  35.     if( c == END_LINE )
  36.       nlines = nlines - 1;
  37.     if( c == BOF_MARK )        /* check for BOF        */
  38.       { set_top_page() ;        /* yes - mark as top of page    */
  39.         return ;
  40.       }
  41.       }                 /* we're before an end_line     */
  42.     get_next_char() ;            /* move past it         */
  43.     set_top_page()  ;            /* mark as top of page        */
  44.   }
  45.  
  46. int set_top_page()
  47.   {
  48.     top_of_page = where_now() ;
  49.   }
  50.